// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database();

//获取查询指令引用
const _ = db.command;

// 云函数入口函数
exports.main = async (event, context) => {
  // 

  //查询条件
  let condition = {};

  //如果按日查询
  if (!event.end) {
    condition = {
      date: event.start,
      userInfo: event.userInfo
    };
  } else {
    //按年、按月查询
    condition.userInfo = event.userInfo;
    condition.date = _.gte(event.start).and(_.lte(event.end));
  }


  try {

    return await db.collection('booking').where(condition).get();

  } catch (err) {
    
  }
}